package sudroid.oauth;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import sudroid.LogUtils;
import sudroid.net2.PostParameter;
import sudroid.security.Base64;

public class OAuth
  implements Serializable
{
  private static final String HMAC_SHA1 = "HmacSHA1";
  private static final PostParameter OAUTH_SIGNATURE_METHOD = new PostParameter("oauth_signature_method", "HMAC-SHA1");
  private static Random RAND = new Random();
  static final long serialVersionUID = -4368426677157998618L;
  private String consumerKey = "";
  private String consumerSecret;

  public OAuth(String paramString1, String paramString2)
  {
    setConsumerKey(paramString1);
    setConsumerSecret(paramString2);
  }

  public static String constructRequestURL(String paramString)
  {
    int i = paramString.indexOf("?");
    if (-1 != i)
      paramString = paramString.substring(0, i);
    int j = paramString.indexOf("/", 8);
    String str1 = paramString.substring(0, j).toLowerCase();
    int k = str1.indexOf(":", 8);
    if (-1 != k)
      if ((!str1.startsWith("http://")) || (!str1.endsWith(":80")))
        break label117;
    for (str1 = str1.substring(0, k); ; str1 = str1.substring(0, k))
      label117: 
      do
      {
        String str2 = String.valueOf(str1);
        StringBuilder localStringBuilder = new StringBuilder(str2);
        String str3 = paramString.substring(j);
        return str3;
      }
      while ((!str1.startsWith("https://")) || (!str1.endsWith(":443")));
  }

  public static String encode(String paramString)
  {
    String str2;
    StringBuffer localStringBuffer1;
    int j;
    try
    {
      String str1 = URLEncoder.encode(paramString, "UTF-8");
      str2 = str1;
      int i = str2.length();
      localStringBuffer1 = new StringBuffer(i);
      j = 0;
      int k = str2.length();
      if (j >= k)
        return localStringBuffer1.toString();
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      throw new RuntimeException("don't support UTF-8.");
    }
    int m = str2.charAt(j);
    if (m == 42)
      StringBuffer localStringBuffer2 = localStringBuffer1.append("%2A");
    while (true)
    {
      j += 1;
      break;
      if (m == 43)
      {
        StringBuffer localStringBuffer3 = localStringBuffer1.append("%20");
        continue;
      }
      if (m == 37)
      {
        int n = j + 1;
        int i1 = str2.length();
        if (n < i1)
        {
          int i2 = j + 1;
          StringBuffer localStringBuffer5;
          if (str2.charAt(i2) == 55)
          {
            int i3 = j + 2;
            if (str2.charAt(i3) == 69)
            {
              StringBuffer localStringBuffer4 = localStringBuffer1.append(126);
              j += 2;
              continue;
            }
          }
        }
      }
      localStringBuffer5 = localStringBuffer1.append(m);
    }
  }

  public static String encodeParameters(List<PostParameter> paramList)
  {
    return encodeParameters(paramList, "&", 0);
  }

  public static String encodeParameters(List<PostParameter> paramList, String paramString, boolean paramBoolean)
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    Iterator localIterator = paramList.iterator();
    while (true)
    {
      if (!localIterator.hasNext())
      {
        if ((localStringBuffer1.length() != 0) && (paramBoolean))
          StringBuffer localStringBuffer2 = localStringBuffer1.append("\"");
        return localStringBuffer1.toString();
      }
      PostParameter localPostParameter = (PostParameter)localIterator.next();
      if (localStringBuffer1.length() != 0)
      {
        if (paramBoolean)
          StringBuffer localStringBuffer3 = localStringBuffer1.append("\"");
        StringBuffer localStringBuffer4 = localStringBuffer1.append(paramString);
      }
      String str1 = encode(localPostParameter.getName());
      StringBuffer localStringBuffer5 = localStringBuffer1.append(str1).append("=");
      if (paramBoolean)
        StringBuffer localStringBuffer6 = localStringBuffer1.append("\"");
      String str2 = encode(localPostParameter.getValue());
      StringBuffer localStringBuffer7 = localStringBuffer1.append(str2);
    }
  }

  public static String normalizeAuthorizationHeaders(List<PostParameter> paramList)
  {
    Collections.sort(paramList);
    return encodeParameters(paramList);
  }

  public static String normalizeRequestParameters(List<PostParameter> paramList)
  {
    Collections.sort(paramList);
    return encodeParameters(paramList);
  }

  public static String normalizeRequestParameters(PostParameter[] paramArrayOfPostParameter)
  {
    return normalizeRequestParameters(toParamList(paramArrayOfPostParameter));
  }

  private void parseGetParameters(String paramString, List<PostParameter> paramList)
  {
    int i = paramString.indexOf("?");
    String[] arrayOfString1;
    if (-1 != i)
    {
      int j = i + 1;
      arrayOfString1 = paramString.substring(j).split("&");
    }
    try
    {
      int k = arrayOfString1.length;
      int m = 0;
      if (m >= k)
        label46: return;
      String[] arrayOfString2 = arrayOfString1[m].split("=");
      if (arrayOfString2.length == 2)
      {
        String str1 = URLDecoder.decode(arrayOfString2[0], "UTF-8");
        String str2 = URLDecoder.decode(arrayOfString2[1], "UTF-8");
        PostParameter localPostParameter1 = new PostParameter(str1, str2);
        boolean bool1 = paramList.add(localPostParameter1);
      }
      while (true)
      {
        m += 1;
        break;
        String str3 = URLDecoder.decode(arrayOfString2[0], "UTF-8");
        PostParameter localPostParameter2 = new PostParameter(str3, "");
        boolean bool2 = paramList.add(localPostParameter2);
      }
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      break label46;
    }
  }

  public static List<PostParameter> toParamList(PostParameter[] paramArrayOfPostParameter)
  {
    int i = paramArrayOfPostParameter.length;
    ArrayList localArrayList = new ArrayList(i);
    List localList = Arrays.asList(paramArrayOfPostParameter);
    boolean bool = localArrayList.addAll(localList);
    return localArrayList;
  }

  public boolean equals(Object paramObject)
  {
    int i;
    if (this == paramObject)
      i = 1;
    while (true)
    {
      return i;
      if (!(paramObject instanceof OAuth))
      {
        i = 0;
        continue;
      }
      OAuth localOAuth = (OAuth)paramObject;
      if (this.consumerKey != null)
      {
        String str1 = this.consumerKey;
        String str2 = localOAuth.consumerKey;
        if (str1.equals(str2));
      }
      else
      {
        do
        {
          i = 0;
          break;
        }
        while (localOAuth.consumerKey != null);
      }
      if (this.consumerSecret != null)
      {
        String str3 = this.consumerSecret;
        String str4 = localOAuth.consumerSecret;
        if (str3.equals(str4));
      }
      else
      {
        do
        {
          i = 0;
          break;
        }
        while (localOAuth.consumerSecret != null);
      }
      i = 1;
    }
  }

  String generateAuthorizationHeader(String paramString1, String paramString2, PostParameter[] paramArrayOfPostParameter, String paramString3, String paramString4, OAuthToken paramOAuthToken)
  {
    if (paramArrayOfPostParameter == null)
      paramArrayOfPostParameter = new PostParameter[0];
    ArrayList localArrayList1 = new ArrayList(5);
    String str1 = this.consumerKey;
    PostParameter localPostParameter1 = new PostParameter("oauth_consumer_key", str1);
    boolean bool1 = localArrayList1.add(localPostParameter1);
    PostParameter localPostParameter2 = OAUTH_SIGNATURE_METHOD;
    boolean bool2 = localArrayList1.add(localPostParameter2);
    PostParameter localPostParameter3 = new PostParameter("oauth_timestamp", paramString4);
    boolean bool3 = localArrayList1.add(localPostParameter3);
    PostParameter localPostParameter4 = new PostParameter("oauth_nonce", paramString3);
    boolean bool4 = localArrayList1.add(localPostParameter4);
    PostParameter localPostParameter5 = new PostParameter("oauth_version", "1.0");
    boolean bool5 = localArrayList1.add(localPostParameter5);
    if (paramOAuthToken != null)
    {
      String str2 = paramOAuthToken.getToken();
      PostParameter localPostParameter6 = new PostParameter("oauth_token", str2);
      boolean bool6 = localArrayList1.add(localPostParameter6);
    }
    int i = localArrayList1.size();
    int j = paramArrayOfPostParameter.length;
    int k = i + j;
    ArrayList localArrayList2 = new ArrayList(k);
    boolean bool7 = localArrayList2.addAll(localArrayList1);
    List localList = toParamList(paramArrayOfPostParameter);
    boolean bool8 = localArrayList2.addAll(localList);
    parseGetParameters(paramString2, localArrayList2);
    StringBuffer localStringBuffer1 = new StringBuffer(paramString1).append("&");
    String str3 = encode(constructRequestURL(paramString2));
    StringBuffer localStringBuffer2 = localStringBuffer1.append(str3).append("&");
    String str4 = encode(normalizeRequestParameters(localArrayList2));
    StringBuffer localStringBuffer3 = localStringBuffer2.append(str4);
    String str5 = localStringBuffer2.toString();
    LogUtils.d("OAuth base string:" + str5);
    String str6 = generateSignature(str5, paramOAuthToken);
    LogUtils.d("OAuth signature:" + str6);
    PostParameter localPostParameter7 = new PostParameter("oauth_signature", str6);
    boolean bool9 = localArrayList1.add(localPostParameter7);
    StringBuilder localStringBuilder = new StringBuilder("OAuth ");
    String str7 = encodeParameters(localArrayList1, ",", 1);
    return str7;
  }

  String generateAuthorizationHeader(String paramString1, String paramString2, PostParameter[] paramArrayOfPostParameter, OAuthToken paramOAuthToken)
  {
    long l1 = System.currentTimeMillis() / 1000L;
    long l2 = RAND.nextInt();
    String str1 = String.valueOf(l1 + l2);
    String str2 = String.valueOf(l1);
    OAuth localOAuth = this;
    String str3 = paramString1;
    String str4 = paramString2;
    PostParameter[] arrayOfPostParameter = paramArrayOfPostParameter;
    OAuthToken localOAuthToken = paramOAuthToken;
    return localOAuth.generateAuthorizationHeader(str3, str4, arrayOfPostParameter, str1, str2, localOAuthToken);
  }

  String generateSignature(String paramString)
  {
    return generateSignature(paramString, null);
  }

  String generateSignature(String paramString, OAuthToken paramOAuthToken)
  {
    char[] arrayOfChar = Base64.encode(paramString.getBytes());
    return new String(arrayOfChar);
  }

  public int hashCode()
  {
    int i;
    int j;
    if (this.consumerKey != null)
    {
      i = this.consumerKey.hashCode();
      j = i * 31;
      if (this.consumerSecret == null)
        break label44;
    }
    label44: for (int k = this.consumerSecret.hashCode(); ; k = 0)
    {
      return j + k;
      i = 0;
      break;
    }
  }

  public void setConsumerKey(String paramString)
  {
    if (paramString != null);
    for (String str = paramString; ; str = "")
    {
      this.consumerKey = str;
      return;
    }
  }

  public void setConsumerSecret(String paramString)
  {
    if (paramString != null);
    for (String str = paramString; ; str = "")
    {
      this.consumerSecret = str;
      return;
    }
  }

  public String toString()
  {
    StringBuilder localStringBuilder1 = new StringBuilder("OAuth{consumerKey='");
    String str1 = this.consumerKey;
    StringBuilder localStringBuilder2 = localStringBuilder1.append(str1).append(39).append(", consumerSecret='");
    String str2 = this.consumerSecret;
    return str2 + 39 + 125;
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.oauth.OAuth
 * JD-Core Version:    0.6.0
 */